<template>
	<view class="mine-content">
		<view class="user-info">
			<view class="info-card">
				<view class="info-detail">
					<image :src="bgImg" mode=""></image>
					<view class="detail-item">
						<view class="tabs-box">
							<view :class="km1?'isSelect':''" @click="handlerClick(1)">科目一</view>
							<view :class="km4?'isSelect':''" @click="handlerClick(4)">科目四</view>
						</view>
						<view class="grade-box">
							<view class="grade-item">
								<view>{{topicNum}}</view>
								<view>累计答题数</view>
								<view>正确率 <text>{{(((topicNum - errtopicNum) / topicNum) * 100).toFixed(2)}}%</text></view>
							</view>
							<view class="grade-item">
								<view>{{km1?subject1_avg_score:subject2_avg_score}}</view>
								<view>考试平均分</view>
								<view>累计考试 <text>{{km1?subject1_exam_count:subject2_exam_count}}次</text></view>
							</view>
							<view class="grade-item">
								<view class="to-test" @click="goExam">去考试</view>
								<view>进入模拟考试<br />全新考题冲刺</view>
							</view>
						</view>
					</view>
				</view>
			</view>
			<view class="menu-list">
				<view class="menu-item" v-for="(item,index) in menuList" :key="index" @click="gotoNext(item.url,item.rightText)">
					<view class="item-left">
						<image :src="item.image" mode=""></image>
						<view>{{item.name}}</view>
					</view>
					<view class="item-right">
						<view :class="item.rightTextColor != '1' ? 'color1' : '' ">{{item.rightText}}</view>
						<image src="../../static/index/right.png" mode=""></image>
					</view>
				</view>
			</view>
		</view>
	</view>
</template>

<script>
	import { getServicePhone } from '@/api/index.js';
	import { getUserInfo,examsInfo,countSet } from '@/api/user.js'
	import { toast } from '../../utils/common';
	import config from '@/config/config.js'
	export default {
		data() {
			return {
				menuList: [{
					image: '../../static/index/wtfk.png',
					name: '我的订单',
					url: '/pagesA/myOrder/index',
					rightText: '',
					rightTextColor: ''
				},
				{
					image: '/static/index/ygsp@3x.png',
					name: '已购视频',
					url: '/pagesA/myOrder/index',
					rightText: '',
					rightTextColor: ''
				},
				{
					image: '/static/index/tjsy@3x.png',
					name: '推荐收益',
					url: '/pagesA/earnings/earnings',
					rightText: '',
					rightTextColor: ''
				},
				{
					image: '/static/index/kscj@3x.png',
					name: '考试成绩',
					url: '/pagesA/testScores/index?type=0',
					rightText: '',
					rightTextColor: ''
				},
				// {
				// 	image: '../../static/index/jsrz.png',
				// 	name: '讲师入驻',
				// 	url: '/pagesA/settled/index',
				// 	rightText: '未入驻',
				// 	rightTextColor: 1
				// },
				{
					image: '../../static/index/wdsc.png',
					name: '我的收藏',
					url: '/pagesA/questionWrong/index?current=1',
					rightText: '',
					rightTextColor: ''
				},
				{
					image: '../../static/index/zhxx.png',
					name: '账户信息',
					url: '/pagesA/accountInfo/index',
					rightText: '',
					rightTextColor: ''
				},
				{
					image: '/static/index/tjm@3x.png',
					name: '我的推荐码',
					url: '/pagesA/share_code/share_code',
					rightText: '',
					rightTextColor: ''
				},
				{
					image: '../../static/index/gywm.png',
					name: '关于我们',
					url: '/pagesA/aboutUs/index',
					rightText: '',
					rightTextColor: ''
				},
				{
					image: '../../static/index/khzx.png',
					name: '客服咨询',
					url: '',
					rightText: '',
					rightTextColor: 2
				}],
				km1:true,
				km4:false,
				subject1_avg_score:0,
				subject1_exam_count:0,
				subject2_avg_score:0,
				subject2_exam_count:0,
				topicNum:uni.getStorageSync('question_count'),
				errtopicNum:uni.getStorageSync('question_error'),
				bgImg: config.baseUrl + '/uploads/images/8o510zke5MnM3Uwwh68csUNGKWZlYNaVYBwoSgL3.png'
			}
		},
		mounted() {
			this.getServicePhone()
			this.getUserInfo()
			this.examsInfo()
		},
		onShow() {
			this.countSet()
		},
		methods:{
			gotoNext(url,str){
				if(url != '' && str == ''){
					uni.navigateTo({
						url
					})
				}
				if(url == '' && str != ''){
					this.telphone(str)
				}
				if(url == '' && str == ''){
					toast('没有获取到客服')
				}
			},
			// 获取用户信息
			getUserInfo() {
				let that = this
				getUserInfo().then(res=>{
					that.is_teacher = res.data.data.is_teacher
					that.menuList.map((item)=>{
						if(item.name == '讲师入驻' && res.data.data.is_teacher != 0){
							item.rightText = '已入驻'
						}
					})
				}).catch()
			},
			// 设置做题数
			countSet(){
				let obj = {
					question_count:uni.getStorageSync('question_count'),//做题总数
					wrong_question_count:uni.getStorageSync('question_error'),//错题总数
				}
				countSet(obj).then(res=>{
					// console.log(5252,res);
				})
			},
			// 获取考试信息
			examsInfo(){
				let that = this
				examsInfo().then(res=>{
					// console.log(96333,res);
					that.subject1_avg_score = res.data.data.subject1_avg_score
					that.subject1_exam_count = res.data.data.subject1_exam_count
					that.subject2_avg_score = res.data.data.subject2_avg_score
					that.subject2_exam_count = res.data.data.subject2_exam_count
				})
			},
			handlerClick(i){
				// console.log(5555,i);
				if(i == 1){
					this.km1 = true;
					this.km4 = false;
				}
				if(i == 4){
					this.km4 = true;
					this.km1 = false;
				}
			},
			// 获取客服电话
			getServicePhone(){
				let that = this
				getServicePhone().then(res=>{
					if(res.data.data.service_phone == null){
					}else{
						// that.servicePhone = res.data.data.service_phone
						that.menuList.map(item=>{
							if(item.name == '客服咨询'){
								item.rightText = res.data.data.service_phone
							}
						})
					}
					// 
				})
			},
			goExam(){
				// 科目一
				if(this.km1){
					uni.navigateTo({
						url: '/pagesA/mockExam/index?type=0&currentTag=' + 1
					})
				}
				// 科目四
				if(this.km4){
					uni.navigateTo({
						url: '/pagesA/mockExam/index?type=1&currentTag=' + 4
					})
				}
			},
			telphone(phone) {
				if(!phone){
					toast('没有客服信息')
					return;
				}
				// 获取设备平台
				const res = uni.getSystemInfoSync();
				// ios系统默认有个模态框
				if (res.platform == 'ios') {
					uni.makePhoneCall({
						phoneNumber: phone,
						success() {
							// console.log('拨打成功了');
						},
						fail() {
							// console.log('拨打失败了');
						}
					})
				} else {
					//安卓手机手动设置一个showActionSheet
					uni.showActionSheet({
						itemList: [phone, '呼叫'],
						success: function(res) {
							if (res.tapIndex == 1) {
								uni.makePhoneCall({
									phoneNumber: phone,
								})
							}
						}
					})
				}
			},
		}
		
	}
</script>

<style lang="scss">
	.color1{
		color: #2AC092;
	}
	.info-card {
		background-color: #2AC092;
		width: 100%;
		height: 200rpx;
		position: relative;

		.info-detail {
			position: absolute;
			position: relative;
			top: 50rpx;
			left: 2%;
			width: 96%;

			>image {
				width: 100%;
				height: 350rpx;
			}

			.detail-item {
				position: absolute;
				top: 0;
				padding: 30rpx;
				width: 100%;

				.tabs-box {
					display: flex;
					border-radius: 50rpx;
					border: 1rpx solid #2AC092;
					width: max-content;
					color: #2AC092;
					overflow: hidden;
					margin-bottom: 50rpx;

					.isSelect {
						background-color: #2AC092;
						color: #fff;
					}

					>view {
						padding: 18rpx 25rpx;
					}

					>view:nth-child(1) {
						border-right: 1rpx solid #2AC092;
					}
				}

				.grade-box {
					display: flex;
					justify-content: space-around;
					align-items: center;

					.grade-item {
						text-align: center;


						>view:nth-child(1) {
							font-size: 36rpx;
						}

						>view:nth-child(2) {
							margin: 20rpx 0;
							font-size: 28rpx;
						}

						>view:last-child {
							font-size: 24rpx;

							>text {
								color: #2AC092;
							}
						}

						.to-test {
							font-size: 26rpx !important;
							background-color: #2AC092;
							color: #fff;
							border-radius: 50rpx;
							padding: 10rpx 25rpx;
						}
					}
				}
			}

		}
	}

	.menu-list {
		width: 96%;
		margin: 230rpx auto;
		border-radius: 10rpx;
		overflow: hidden;
		padding: 0 20rpx;
		background-color: #fff;

		.menu-item {
			padding: 30rpx 10rpx;
			display: flex;
			justify-content: space-between;
			border-bottom: 1px solid #E6E6E6;

			.item-left {
				display: flex;
				font-size: 30rpx;
				align-items: center;
				color: #333;

				>image {
					width: 44rpx;
					height: 44rpx;
					margin-right: 30rpx;
				}
			}

			.item-right {
				display: flex;
				align-items: center;
				font-size: 28rpx;
				color: #333;

				>image {
					width: 30rpx;
					height: 30rpx;
				}
			}
		}
	}
</style>